/**
 * javascript分页
 * @param {Object} recordCount 记录数
 * @param {Object} currentPage 当前页码
 * @param {Object} pageSize 每页记录数
 * @param {Object} pageCount 总页数
 * @param {Object} pagerID 分页条展示在指定html元素中
 */
function RenderPager(recordCount,currentPage,pageSize,pageCount,pagerID) {
	var count = recordCount;
	var perpage = pageSize;
	var currentpage = currentPage
	var pagecount = pageCount;
	var pagestr = "";
	var breakpage = 5;
	var currentposition = 4;
	var breakspace = 2;
	var maxspace = 4;
	var prevnum = currentpage-currentposition;
	var nextnum = currentpage+currentposition;
	if(prevnum<1) prevnum = 1;
	
	if(count == 0) return false;
	if(nextnum>pagecount) nextnum = pagecount;
	pagestr += '<div class=\"paginator\">';
	//console.error(pagerID);
	pagestr+=(currentPage==1)?'<span class=\"prev\">&lt;前页</span>':'<span class=\"prev\"><a href="#" onclick=RenderPager('+recordCount+','+parseInt(currentPage-1)+','+pageSize+','+pageCount+',"'+pagerID+'");showTable('+parseInt(currentPage-1)+','+pageSize+');>&lt;前页</a></span>';
	if(prevnum-breakspace>maxspace){
		for(i=1;i<=breakspace;i++)
			pagestr += '<a href="#" onclick=RenderPager('+recordCount+','+i+','+pageSize+','+pageCount+',"'+pagerID+'");showTable('+i+','+pageSize+');>'+i+'</a>';
		pagestr += '<span class="break">...</span>';
		for(i=pagecount-breakpage+1;i<prevnum;i++)
			pagestr += '<a href="#" onclick=RenderPager('+recordCount+','+i+','+pageSize+','+pageCount+',"'+pagerID+'");showTable('+i+','+pageSize+');>'+i+'</a>';
	}else{
		for(i=1;i<prevnum;i++)
			pagestr += '<a href="#" onclick=RenderPager('+recordCount+','+i+','+pageSize+','+pageCount+',"'+pagerID+'");showTable('+i+','+pageSize+');>'+i+'</a>';
	}
	for(i=prevnum;i<=nextnum;i++){
		pagestr += (currentpage==i)?'<span class=\"thispage\">'+i+'</span>':'<a href="#" onclick=RenderPager('+recordCount+','+i+','+pageSize+','+pageCount+',"'+pagerID+'");showTable('+i+','+pageSize+');>'+i+'</a>';
	}
	if(pagecount-breakspace-nextnum+1>maxspace){
		for(i=nextnum+1;i<=breakpage;i++)
			pagestr += '<a href="#" onclick=RenderPager('+recordCount+','+i+','+pageSize+','+pageCount+',"'+pagerID+'");showTable('+i+','+pageSize+');>'+i+'</a>';
		pagestr += '<span class="break">...</span>';
		for(i=pagecount-breakspace+1;i<=pagecount;i++)
			pagestr += '<a href="#" onclick=RenderPager('+recordCount+','+i+','+pageSize+','+pageCount+',"'+pagerID+'");showTable('+i+','+pageSize+');>'+i+'</a>';
	}else{
		for(i=nextnum+1;i<=pagecount;i++)
			pagestr += '<a href="#" onclick=RenderPager('+recordCount+','+i+','+pageSize+','+pageCount+',"'+pagerID+'");showTable('+i+','+pageSize+');>'+i+'</a>';
	}	
	pagestr += (currentpage==pagecount)?'<span class=\"next\">后页&gt;</span>':'<span class=\"next\"><a href="#" onclick=RenderPager('+recordCount+','+parseInt(currentPage+1)+','+pageSize+','+pageCount+',"'+pagerID+'");showTable('+parseInt(currentPage+1)+','+pageSize+');>后页&gt;</a></span><div>';
	
	document.getElementById(pagerID).innerHTML = pagestr;
}